<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>模块管理</title> {{>/WEB-INF/pages/common/meta_base.part.html}}
{{>/WEB-INF/pages/common/refs_base.part.html}}
{{>/WEB-INF/pages/common/refs_modal.part.html}}
{{>/WEB-INF/pages/common/refs_plupload.part.html}}
</head>
<body>
	<!-- <div class="container"> -->
	{{>/WEB-INF/pages/common/layout_header.part.html}}

	<div class="container">
		<ul class="breadcrumb">
			<li><a href="{{ctx}}">首页</a></li>
			<li><a href="{{ctx}}/mam/widget/list-view">模块管理</a></li>
			<li><a href="{{ctx}}/mam/widget/widget-view/{{widgetVO.id}}">{{widgetVO.name}}</a></li>
			<li class="active">{{versionVO.version}}</li>
		</ul>
		<hr class="hr1" />
		<div class="hr-10"></div>
		<div class="bor-tab bg-st-white text-center">
			<div class="mar-st-a30">
				<div class="pad-st-b10 row">
					<div class="col-sm-12">

						<div class="text-right pad-st-b5">
							<a class="btn btn-primary btn-small tls"
								href="javascript:deleteWidgetVersion('{{versionVO.id}}')">删除</a>
							<a class="btn btn-primary btn-small tls"
								onclick="versionEdit('{{versionVO.id}}')">编 辑</a>
						</div>

						<div class="col-sm-2">
							<img style="width: 106px; height: 106px; cursor: pointer"
								class="img-rounded info-icon" id="widgetIcon" />
							<p>
								<strong>版本号：{{versionVO.version}} </strong>
							</p>
						</div>
						<script type="text/javascript">
							var icon_id = "{{widgetVO.icon_id}}";
							if (icon_id != "") {
								jQuery("#widgetIcon")
										.attr("src",
												"{{ctx}}/mam/attachment/download/{{widgetVO.icon_id}}");
							} else {
								jQuery("#widgetIcon").attr("src",
										"{{ctx}}/static/bsl/images/defind.png");
							}
						</script>
						<div class="col-sm-10 text-left">
							<ul class="list-li" style="width: 30%">
								<li>模块名称：{{widgetVO.name}}</li>
								<li>模块标识：{{widgetVO.identify}}</li>
								<li>模块类别：{{categoryVO.name}}</li>
								<li>&nbsp;&nbsp;构建号 ：{{versionVO.build}}</li>

								<li class="NotShowWhenLocal">文件大小：<script
										type="text/javascript">
									document.write(plupload
											.formatSize('{{versionVO.size}}'))
								</script></li>
								<li>创建时间：<script type="text/javascript">
									document.write($.format.date(
											"{{versionVO.created_at}}",
											"yyyy-MM-dd HH:mm"))
								</script></li>
								<li>更新时间：<script type="text/javascript">
									document.write($.format.date(
											"{{versionVO.modified_at}}",
											"yyyy-MM-dd HH:mm"))
								</script></li>
								<li>版本简介：<span style="width: 100%; word-wrap: break-word;">{{versionVO.release_not}}</span></li>
								<li class="NotShowWhenLocal">&nbsp;&nbsp;安装包： <a
									class="btn-info btn-sm"
									href="{{ctx}}/mam/attachment/download/{{versionVO.boundle}}">下
										载</a></li>
							</ul>
						</div>
					</div>
				</div>
				<div class="hr-10"></div>
			</div>
		</div>
	</div>
	<div class="container bor-tab bg-st-white" id="appContainer"
		style="display:">
		<div class="tit2-st">关联应用</div>
		<div class="bor-top text-center">
			{{#appList}}
			<ul style="float: left; margin-top: 10px; width: 15%; height: 160px">
				<li><a href="javascript:showAppView('{{app.id}}')">
						<p>
							<img class="img-rounded info-icon" id="{{app.icon}}"
								style="height: 72px; width: 72px;" />
						</p>
				</a></li>
				<li>{{app.app_name}}({{appVersion.platformid}})-{{appVersion.version}}</li>
				<li>
					<div>
						<img class="img-circle delete-icon" data-toggle="tooltip"
							data-placement="right" title="删除关联" style="cursor: pointer"
							src="{{ctx}}/static/bsl/images/XX.png"
							onclick="deleteAppRelaction('{{appVersion.platformid}}','{{appVersion.version}}','{{app.id}}','{{versionVO.version}}','{{versionVO.widget_id}}')" />
					</div>
				</li>
			</ul>
			{{/appList}}

		</div>
		<div class="hr"></div>
	</div>

	<div class="container bor-tab bg-st-white">
		<div class="tit2-st">
			<span>模块快照 </span>
		</div>
		<div class="text-right pad-st-b5">
			<a class="btn btn-primary btn-small tls"
				href="javascript:enterAddSnaphot('{{versionVO.id}}')">新增快照</a>
		</div>
		<div class="bor-top">
			<div class="bor-top">
				{{#listSnapshot}}
				<div class="col-sm-2 text-center pad-st-b10" id="noIcon">
					<ul class="ul_four nocircle">
						<li><img class="info-icon"
							src="{{ctx}}/mam/attachment/download/{{snapshot}}"
							style="height: 90px; width: 90px;" /></li>
						<li><img class="img-circle delete-icon" data-toggle="tooltip"
							data-placement="right" title="删除" style="cursor: pointer"
							src="{{ctx}}/static/bsl/images/XX.png"
							onclick="deleteSnaphot('{{id}}')" /></li>
					</ul>

				</div>
				{{/listSnapshot}}

			</div>
			<div class="hr"></div>
		</div>
	</div>
	<!--boostrap 弹框 -->
	{{>/WEB-INF/pages/app/widget-modal.html}}
	{{>/WEB-INF/pages/common/layout_footer.part.html}}
</body>
</html>
<script type="text/javascript">
	$(function() {

		$('#appContainer').find("a").each(function(index) {
			var img = $(this).find('img');
			var icon = $(img).attr("id");
			if (icon != "") {
				$(img).attr("src", "{{ctx}}/mam/attachment/download/" + icon);
			} else {
				$(img).attr("src", "{{ctx}}/static/bsl/images/defind.png");
			}
		});

		if ('{{widgetVO.local}}' != '') {
			$(".NotShowWhenLocal").hide();
		}
		var app = ('{{#appList}}{{.}}{{/appList}}');
		if (app === "") {
			$("#appContainer").hide();
		}
	})
	function versionAdd(id) {
		window.location.href = "{{ctx}}/mam/widgetVersion/add-view?widgetID="
				+ id;
	}

	//编辑
	function versionEdit(versionId) {
		var op = {
			remote : '{{ctx}}/mam/widgetVersion/update-view/' + versionId,
			show : true
		};
		$('#btn_modal').unbind();
		$('#btn_modal').bind("click", function() {
			formSubmit();
		});
		$('#myModal').modal(op);
	}

	function showVersionView(id) {
		window.location.href = "{{ctx}}/mam/widgetVersion/view?id=" + id;
	}

	function showAppView(appId) {
		window.location.href = "{{ctx}}/mam/appMain/app-view/" + appId;
	}

	function deleteWidgetVersion(id) {
		bootbox
				.confirm(
						"确定要删除吗?",
						function(result) {
							if (result) {
								$
										.ajax({
											type : "GET",
											dataType : "json",
											url : "{{ctx}}/mam/widgetVersion/delete?id="
													+ id,
											success : function(data, textStatus) {
												var url = "{{ctx}}/mam/widget/widget-view/{{widgetVO.id}}";
												if (data.result == "success") {
													window.location.href = url;
												} else {
													bootbox
															.alert("删除失败，请稍后再试！");
												}
											},
											error : function(data, status, e) {
												bootbox.alert("系统繁忙，请稍后再试！");
											}
										});
							}
						});
	}

	function deleteAppRelaction(platform,appVersion,appId,widgetVersion,widgetId) {
		bootbox.confirm("确定要删除吗?", function(result) {
			if (result) {
				$.ajax({
					type : "DELETE",
					dataType : "json",
					url : "{{ctx}}/mam/appwidgets/delrelations/" + 
							platform + "/"+ appVersion + "/"+ appId + "/"+ widgetVersion + "/"+ widgetId + "/",
					success : function(data, textStatus) {
						if (data.result == "success") {
							window.location.reload();
						} else {
							bootbox.alert("删除失败，请稍后再试！");
						}
					},
					error : function(data, status, e) {
						bootbox.alert("系统繁忙，请稍后再试！");
					}
				});
			}
		});
	}

	//进入添加快照页面
	function enterAddSnaphot(versionId) {
		var loadurl = '{{ctx}}/mam/widgetSnapshot/add-view/' + versionId;
		$.get(loadurl, function(data) {
			bootbox.dialog({
				message : data,
				title : "模块快照",
				buttons : {
					danger : {
						label : "关闭",
						className : "btn btn-common btn-small tls"
					},

					success : {
						label : "保存",
						className : "btn btn-primary btn-small tls",
						callback : function() {
							widgetSnaphsotSbumit();
							return false;
						}
					}
				}
			});
		});
	}

	function deleteSnaphot(id) {
		bootbox.confirm("确定要删除吗?", function(result) {
			if (result) {
				$.ajax({
					type : "DELETE",
					dataType : "json",
					url : "{{ctx}}/mam/widgetSnapshot/delete?id=" + id,
					success : function(data, textStatus) {
						if (data.result == "success") {
							window.location.reload();
						} else {
							bootbox.alert("删除失败，请稍后再试！");
						}
					},
					error : function(data, status, e) {
						bootbox.alert("系统繁忙，请稍后再试！");
					}
				});
			}
		});
	}
</script>
